//
// Created by Amon on 2021/11/13.
//

#ifndef AMONPLAYER_IOCANARY_H
#define AMONPLAYER_IOCANARY_H

#include <string>
#include <map>
#include <jni.h>

namespace iocanary {
    void init(JNIEnv *env);

    typedef struct {
        JNIEnv *jniEnv;
        jclass file_io_canary_java_clazz;
        jmethodID get_java_stack_mid;
    } _iocanary_java;

    class FileInfo {
    public:
        FileInfo(std::string _file_path, std::string _java_stack) :
                file_path(_file_path), java_stack(_java_stack) {

        }

        long total_cost_time = 0;
        long buffer_size = 0;
        std::string file_path;
        std::string java_stack;
    };

    class IoCanary {
    public:
        void OnOpen(int fd, const std::string &file_path);

        void OnRead(int i, ssize_t i1, int64_t i2);

        void OnWrite(int i, ssize_t i1, int64_t i2);

        void OnClose(int fd);

    private:
        std::map<int, FileInfo *> info_map;
    };
}

#endif //AMONPLAYER_IOCANARY_H
